package china.nanjing.mykingdom.controller;

import china.nanjing.mykingdom.service.MilitaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.math.BigDecimal;


/**
 * @author Chen Hongyu
 */
@RestController
@Slf4j
public class MilitaryController {

    @Autowired
    @Qualifier(value = "militaryService")
    private MilitaryService militaryService;

    /**
     * 计算公国总军力
     *
     * @param duchyId 公国ID
     * @return 响应
     */
    @PostMapping(value = "/duchy_military_strength")
    // 参数多建议封装对象，然后用@RequestBody
    public Object computeDuchyMilitaryStrengthById(@RequestParam(value = "duchy_id") Long duchyId) {
        log.info("####MilitaryController.computeDuchyMilitaryStrengthById invoked####");
        // TODO 封装响应对象
        return militaryService.computeDuchyMilitaryStrength(duchyId);
    }

    /**
     * 计算王国总军力，按名称搜索
     *
     * @param kingdoName 王国名
     * @return 响应
     */
    @PostMapping(value = "/kingdom_military_strength_by_name")
    public Object computeKingdomMilitaryStrengthByName(@RequestParam(value = "kingdomName") String kingdoName) {
        return militaryService.computeKingdomMilitaryStrengthByName(kingdoName);
    }

    /**
     * 计算王国总军力，按名称搜索, WebFlux版
     *
     * @param kingdoName 王国名
     * @return 响应
     */
    @PostMapping(value = "/kingdom_military_strength_by_name_webFlux")
    public Mono<BigDecimal> computeKingdomMilitaryStrengthByNameWebFlux(@RequestParam(value = "kingdomName") String kingdoName) {
        BigDecimal total = militaryService.computeKingdomMilitaryStrengthByName(kingdoName);
        return Mono.just(total);
    }

}
